//
//  SKFoodDetailViewController.m
//  Gastrosoph
//
//  Created by 张明磊 on 12-10-19.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "SKFoodDetailViewController.h"
#import "SKCustomNavigationBar.h"
#import "SKHeaderFiles.h"
#import "SKFoodDetailTableCell.h"
#import "SKModel_foodDetail.h"



#define SK_BUTTON_RETURN_CGRECT CGRectMake(10, 4, 56, 36)

#define SK_BUTTON_FILLTER_CGRECT CGRectMake(265, 4, 42, 35)

#define SK_LABEL_TITLEFOODNAME_CGRECT CGRectMake(106, 0, 159, 30)

#define SK_LABEL_TITLEFOODLOCATION_CGRECT CGRectMake(108, 20, 157, 26)

#define SK_TABLEVIEW_FOODDETAIL_CGRECT CGRectMake(0, 44, 320, 416)



typedef enum
{
    SKButtonTag_return   = 0,
    SKButtonTag_fillter     ,
    
}SKButtonTag;


@interface SKFoodDetailViewController ()

@end

@implementation SKFoodDetailViewController


@synthesize cell_foodDetailCell = _cell_foodDetailCell;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self)
    {
        // Custom initialization
    }
    return self;
}

- (id)initWithModel:(SKModel_foodTopRank *)_model
{
    self = [super init];
    
    if(self)
    {
        [self install_view_titleWithModel:_model];
        
        [self install_view_TableWithModel:_model];
        
        UIImage *image_foodOne = [UIImage imageNamed:@"test_foodImage.png"];
        
        UIImage *image_foodTwo = [UIImage imageNamed:@"test_foodImage2.png"];
        
        UIImage *image_food1 = [UIImage imageNamed:@"test_youlike1.png"];
        
        UIImage *image_food2 = [UIImage imageNamed:@"test_youlike2.png"];
        
        UIImage *image_food3 = [UIImage imageNamed:@"test_youlike3.png"];
        
        UIImage *image_food4 = [UIImage imageNamed:@"test_youlike4.png"];
  
        NSArray *array_foodPhoto = [NSArray arrayWithObjects:image_foodOne,image_foodTwo,nil];
        
        NSArray *array_youLike = [NSArray arrayWithObjects:image_food1,image_food2,image_food3,image_food4,nil];
        
        model_foodDetail = [[SKModel_foodDetail alloc] initWithfoodTopRankModel:_model integerCommentCount:4 restaurantLocation:@"魏公村民族大学北路18号,海淀区,北京市" foodCost:@"150元" styleOfCooking:@"西餐" restaurantPhone:@"电话 : 010-86924918" otherFoodPhoto:array_foodPhoto youLikeFoodPhoto:array_youLike];
    }
    
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];  
	// Do any additional setup after loading the view.
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (void)dealloc
{
    [_cell_foodDetailCell release], _cell_foodDetailCell = nil;
    
    [super dealloc];
}


#pragma mark - 
#pragma mark InstallViewController


- (void)install_view_titleWithModel:(SKModel_foodTopRank *)_model
{
    SKCustomNavigationBar *customNavigationBar = [[SKCustomNavigationBar alloc] initWithFrame:SK_NAVIGATIONBAR_CGRECT];
    
    UIButton *button_return = [UIButton buttonWithType:UIButtonTypeCustom];
    
    [button_return setFrame:SK_BUTTON_RETURN_CGRECT];
    
    [button_return setBackgroundImage:[UIImage imageNamed:@"button_foodDetail_return.png"] forState:UIControlStateNormal];
    
    [button_return setBackgroundImage:[UIImage imageNamed:@"button_foodDetail_return_pressed.png"] forState:UIControlStateHighlighted];
    
    [button_return.titleLabel setFont:[UIFont fontWithName:SK_TEXTFONT size:18.0] ];
    
    [button_return setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    
    [button_return setTitle:@"返回" forState:UIControlStateNormal];
    
    [button_return setTag:SKButtonTag_return];
    
    [button_return addTarget:self action:@selector(didClickButton_foodDetail:) forControlEvents:UIControlEventTouchUpInside];
    
    [customNavigationBar addSubview:button_return];
    
    UIButton *button_fillter = [UIButton buttonWithType:UIButtonTypeCustom];
    
    [button_fillter setFrame:SK_BUTTON_FILLTER_CGRECT];
    
    [button_fillter setBackgroundImage:[UIImage imageNamed:@"button_fillter.png"] forState:UIControlStateNormal];
    
    [button_fillter setBackgroundImage:[UIImage imageNamed:@"button_fillter_pressed.png"] forState:UIControlStateHighlighted];
    
    [button_fillter setTag:SKButtonTag_fillter];
    
    [button_fillter addTarget:self action:@selector(didClickButton_foodDetail:) forControlEvents:UIControlEventTouchUpInside];
    
    [customNavigationBar addSubview:button_fillter];
    
    UILabel *label_foodName = [[UILabel alloc]initWithFrame:SK_LABEL_TITLEFOODNAME_CGRECT];
    
    [label_foodName setBackgroundColor:[UIColor clearColor]];
    
    [label_foodName setTextColor:[UIColor whiteColor]];
    
    [label_foodName setFont:[UIFont fontWithName:SK_TEXTFONT size:18.0]];
    
    [label_foodName setText:_model.string_foodName];
    
    [customNavigationBar addSubview:label_foodName];
    
    [label_foodName release];
    
    UILabel *label_foodLocation = [[UILabel alloc] initWithFrame:SK_LABEL_TITLEFOODLOCATION_CGRECT];
    
    [label_foodLocation setTextColor:[UIColor grayColor]];
    
    [label_foodLocation setBackgroundColor:[UIColor clearColor]];
    
    [label_foodLocation setFont:[UIFont fontWithName:SK_TEXTFONT size:13.0]];
    
    [label_foodLocation setText:_model.string_restaurantName];
    
    [customNavigationBar addSubview:label_foodLocation];
    
    [label_foodLocation release];
    
    [self.view addSubview:customNavigationBar];
    
    [customNavigationBar release];
}

- (void)install_view_TableWithModel:(SKModel_foodTopRank *)_model
{
    UITableView *tableView_foodDetail = [[UITableView alloc] initWithFrame:SK_TABLEVIEW_FOODDETAIL_CGRECT];
    
    [tableView_foodDetail setDataSource:self];
    
    [tableView_foodDetail setDelegate:self];
    
    [self.view addSubview:tableView_foodDetail];
    
    [tableView_foodDetail release];
}



#pragma mark - 
#pragma didClickButton

- (void)didClickButton_foodDetail:(id)sender
{
    UIButton *button_tmp = (UIButton *)sender;
    
    switch (button_tmp.tag)
    {
        case SKButtonTag_return:
        {
            [self dismissViewControllerAnimated:NO completion:nil];       
        }
        break;  
            
        case SKButtonTag_fillter:
        {
            
        }
        break;
            
        default:
            break;
    }
}


#pragma mark -
#pragma mark UITableViewDataSource

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView  dequeueReusableCellWithIdentifier:CellIdentifier];
    
    if (cell == nil)
    {
        _cell_foodDetailCell = nil;
                
        self.cell_foodDetailCell = [[[SKFoodDetailTableCell alloc]initwithModel:model_foodDetail] autorelease];
        
        [model_foodDetail release];
        
        cell = _cell_foodDetailCell;
    }
    
    
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    
    [cell.contentView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"view_shake_background.png"]]];
    
    return cell;
    
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

#pragma mark - 
#pragma mark UITableViewDelegate

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 920;
}



@end
